using UnityEngine;
using System.Collections;

public class DeathScript : MonoBehaviour {
	public Transform spawn;
	private Controllers controllerScript;
	public int numRandomObjects = 10;
	// Use this for initialization
	void Start () {
		controllerScript = spawn.GetComponent<Controllers>();
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnTriggerEnter(Collider other)
	{
		if(other.tag == "Player")
		{
			Vector3 pos = other.gameObject.transform.position;
			Destroy(other.gameObject);
			controllerScript.sp.WriteLine("1");
			for( int i = 0; i < numRandomObjects; i++)
			{
				GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Cube);
				sphere.transform.localScale = new Vector3(5, 5, 5);
				sphere.transform.position = pos;
				sphere.AddComponent("Rigidbody");
				int force1 = Random.Range(-500, 500);
				int force2 = Random.Range(-500, 500);
				int force3 = Random.Range(250, 500);
				sphere.transform.rigidbody.AddTorque(force1, force2, force3);
				sphere.transform.rigidbody.AddForce(0, force2, force3);
			}
		}
	}
}
